<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true" label-width="400px">
      <el-form-item label="cloak服务商选择" prop="cloak_choice" label-width="120px">
        <el-select v-model="form.cloak_choice" placeholder="请选择cloak服务商" clearable size="small">
          <el-option
            v-for="item in cloakOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">保存</el-button>
      </el-form-item>
    </el-form>
    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="success"-->
    <!--          icon="el-icon-edit"-->
    <!--          size="mini"-->
    <!--          @click="submitForm"-->
    <!--        >提交</el-button>-->
    <!--      </el-col>-->

    <!--    </el-row>-->
    <!--    <el-table v-loading="loading" :data="cloakChoiceList" @selection-change="handleSelectionChange">-->
    <!--          <el-table-column type="selection" width="55" align="center" />-->
    <!--             <el-table-column label="id" align="center" prop="id" />-->
    <!--             <el-table-column label="cloak服务商选择" align="center" prop="cloak_choice" />-->
    <!--          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
    <!--            <template slot-scope="scope">-->
    <!--              <el-button-->
    <!--                size="mini"-->
    <!--                type="text"-->
    <!--                icon="el-icon-edit"-->
    <!--                @click="handleUpdate(scope.row)"-->
    <!--              >修改</el-button>-->
    <!--              <el-button-->
    <!--                size="mini"-->
    <!--                type="text"-->
    <!--                icon="el-icon-delete"-->
    <!--                @click="handleDelete(scope.row)"-->
    <!--              >删除</el-button>-->
    <!--            </template>-->
    <!--          </el-table-column>-->
    <!--        </el-table>-->
    <!--        <pagination-->
    <!--              v-show="total>0"-->
    <!--              :total="total"-->
    <!--              :page.sync="queryParams.pageNum"-->
    <!--              :limit.sync="queryParams.pageSize"-->
    <!--              @pagination="getList"-->
    <!--            />-->
    <!--            &lt;!&ndash; 添加或修改cloak服务商选择对话框 &ndash;&gt;-->
    <!--                <el-dialog :close-on-click-modal=false :title="title" :visible.sync="open" width="500px" append-to-body>-->
    <!--                  <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
    <!--                    <el-form-item label="用户ID" prop="user_id">-->
    <!--                      <el-input v-model="form.user_id" placeholder="请输入用户ID" />-->
    <!--                    </el-form-item>-->
    <!--          </el-form>-->
    <!--          <div slot="footer" class="dialog-footer">-->
    <!--            <el-button type="primary" @click="submitForm">确 定</el-button>-->
    <!--            <el-button @click="cancel">取 消</el-button>-->
    <!--          </div>-->
    <!--        </el-dialog>-->
  </div>
</template>
<script>
import {listCloakChoice, getCloakChoiceSelect, addCloakChoice, updateCloakChoice} from '@/api/cloakConfig/cloakChoice'

export default {
  name: "cloakChoice",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // cloak服务商选择表格数据
      cloakChoice: "",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      cloakOptions: [{
        value: 'cloakplus',
        label: 'cloakplus'
      }, {
        value: 'fraudfilter',
        label: 'fraudfilter'
      }, {
        value: 'trafficarmor',
        label: 'trafficarmor'
      }],
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getSelect();
  },
  methods: {
    /** 查询cloak服务商选择列表 */
    getSelect() {
      this.loading = true;
      getCloakChoiceSelect().then(response => {
        this.cloakChoice = response.data.cloak_choice;
        this.form = response.data;
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form.id)
          if (this.form.id != null) {
            updateCloakChoice(this.form).then(response => {
              if (response.code === 0) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getSelect();
              }
            });
          } else {
            addCloakChoice(this.form).then(response => {
              if (response.code === 0) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getSelect();
              }
            });
          }
        }
      });
    },
  } //methods结束
};
</script>
